<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <h:head>
        <title>MeteoCal - Welcome #{userBean.username}</title>
    </h:head>

    <h:body>
        <p:layout style="min-width:1000px;min-height:1000px;">
            
            <p:layoutUnit position="west" resizable="true" size="220" minSize="80" maxSize="300">
                <h:form id="button">
                    <br></br>
                    <p:commandButton id="viewPersonal" value="Personal Page" action="#{searchUserBean.uploadPersonalPage()}" ajax="true" style="width:200px;height:50px;margin-left: 5px;margin-right: 5px">  
                    </p:commandButton>
                    <br></br><br></br>
                    <p:commandButton id="newEvent" value="New Event" action="new-event" ajax="true" style="width:200px;height:50px;margin-left: 5px;margin-right: 5px">
                    </p:commandButton>
                    <br></br><br></br>
                    <p:commandButton id="searchUser" value="Browse User" action="#{searchBean.browseUsers()}" ajax="true" style="width:200px;height:50px;margin-left: 5px;margin-right: 5px">
                    </p:commandButton>
                    <br></br><br></br>
                    <p:commandButton id="searchEvent" value="Search Event" action="search-event-page" ajax="true" style="width:200px;height:50px;margin-left: 5px;margin-right: 5px">  
                    </p:commandButton>
                    <br></br><br></br>
                    <p:commandButton id="logout" value="Logout" action="#{loginBean.logout()}" style="width:200px;height:50px;margin-left: 5px;margin-right: 5px">
                    </p:commandButton>
                    <br></br><br></br>
                    </h:form>
            </p:layoutUnit>
          
            <p:layoutUnit position="center" resizable="true" size="500" minSize="200" maxSize="1000">
                
                <p:schedule id="schedule" value="#{showCalendarBean.eventModel}" widgetVar="myschedule" timeZone="GMT+2">
                    <p:ajax event="dateSelect" listener="#{showCalendarBean.onDateSelect}" update="eventDetails" oncomplete="PF('eventDialog').show();" />
                    <p:ajax event="eventSelect" listener="#{showCalendarBean.onEventSelect}" update="eventDetails" oncomplete="PF('eventDialog').show();" />  
                </p:schedule>  

                <p:dialog widgetVar="eventDialog" header="Event Details" showEffect="clip" hideEffect="clip">

                    <h:panelGrid id="eventDetails" columns="2">  
                        <h:outputLabel for="name" value="Name:" />  
                        <p:inputText id="title" value="#{showCalendarBean.event.title}" readonly="true"/>

                        <h:outputLabel for="from" value="From:" />  
                        <p:inputMask id="from" mask="99/99/9999" value="#{showCalendarBean.event.startDate}" readonly="true">  
                            <f:convertDateTime pattern="dd/MM/yyyy" />  
                        </p:inputMask>  

                        <h:outputLabel for="to" value="To:" />  
                        <p:inputMask id="to" mask="99/99/9999" value="#{showCalendarBean.event.endDate}" readonly="true">  
                            <f:convertDateTime pattern="dd/MM/yyyy" />  
                        </p:inputMask>

                    </h:panelGrid>  
                </p:dialog>
                <br></br><br></br>
            </p:layoutUnit> 
        </p:layout>
                
                <p:dataList id="invitation_list" value="#{showCalendarBean.eventInvitationList}" var="invitation" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                    <f:facet name="header">
                        Invitation List
                    </f:facet>
                    <p:commandLink update=":evform:invitationDetail" oncomplete="PF('invitationDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search" >
                        <f:setPropertyActionListener value="#{invitation}" target="#{showCalendarBean.eventSelected}" />
                        <h:outputText value="#{invitation.name}, #{invitation.place}" />
                    </p:commandLink>
                    <h:outputText id="event_review" style="display:inline-block">#{invitation.name}, #{invitation.place}</h:outputText>
                    <h:outputText value="#{invitation.name}, #{invitation.place}" style="display:inline-block"/>
                </p:dataList>

                <p:dialog id="evDtsWindow" header="Invitation Informations" widgetVar="invitationDialog" modal="true" showEffect="blind" resizable="false">
                    <h:form id="evform">
                        <p:outputPanel id="invitationDetail" style="text-align:center;">
                            <p:panelGrid  columns="2" rendered="#{not empty showCalendarBean.eventSelected}" columnClasses="label,value">

                                <h:outputText value="Name:" />
                                <h:outputText value="#{showCalendarBean.eventSelected.name}" />

                                <h:outputText value="Starting Date" />
                                <h:outputText value="#{showCalendarBean.eventSelected.starting_date}" />

                                <h:outputText value="Starting Time" />
                                <h:outputText value="#{showCalendarBean.eventSelected.startingTime.hours}:#{showCalendarBean.eventSelected.startingTime.minutes}" />

                                <h:outputText value="Ending Date" />
                                <h:outputText value="#{showCalendarBean.eventSelected.ending_date}" />

                                <h:outputText value="Ending Time" />
                                <h:outputText value="#{showCalendarBean.eventSelected.endingTime.hours}:#{showCalendarBean.eventSelected.endingTime.minutes}" />

                                <h:outputText value="Place" />
                                <h:outputText value="#{showCalendarBean.eventSelected.place}" />


                            <p:commandButton id="No" value="No" action="#{showCalendarBean.deleteInvitedUser()}" ajax="false" styleClass="ui-confirmdialog-no" icon="ui-icon-close">
                                <f:setPropertyActionListener value="#{showCalendarBean.eventSelected}" target="#{showCalendarBean.eventoSelezionato}" /> 
                            </p:commandButton>
                            <p:commandButton id="Yes" value="Yes" action="#{showCalendarBean.insertInvitedUser()}" ajax="false" styleClass="ui-confirmdialog-yes" icon="ui-icon-check">
                             <f:setPropertyActionListener value="#{showCalendarBean.eventSelected}" target="#{showCalendarBean.eventoSelezionato}" />    
                            </p:commandButton>
                            </p:panelGrid>
                        </p:outputPanel>
                    </h:form>
                </p:dialog>
                <p:dataList id="cancellation_list" value="#{showCalendarBean.eventCancellationList}" var="cancellation" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                    <f:facet name="header">
                        Cancellation List
                    </f:facet>
                    <p:commandLink update=":form:cancellationDetail" oncomplete="PF('cancellationDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search" style="float:left;margin-right:10px">
                        <f:setPropertyActionListener value="#{cancellation}" target="#{showCalendarBean.eventSelectedDeleted}" />
                        <h:outputText value="#{cancellation.name}, #{cancellation.place}" />
                    </p:commandLink>
                    <h:outputText id="event_review" style="display:inline-block">#{cancellation.name}, #{cancellation.place}</h:outputText>
                    <h:outputText value="#{cancellation.name}, #{cancellation.place}" style="display:inline-block"/>
                </p:dataList>
                <p:dialog id="evcDtsWindow" header="Cancellated Events" widgetVar="cancellationDialog" modal="true" showEffect="blind" resizable="false">
                    <h:form id="form">
                        <p:outputPanel id="cancellationDetail" style="text-align:center;">
                            <p:panelGrid  columns="2" rendered="#{not empty showCalendarBean.eventSelectedDeleted}" columnClasses="label,value">

                                <h:outputText value="Name:" />
                                <h:outputText value="#{showCalendarBean.eventSelectedDeleted.name}" />

                                <h:outputText value="Starting Date" />
                                <h:outputText value="#{showCalendarBean.eventSelectedDeleted.startingDate}" />

                                <h:outputText value="Place" />
                                <h:outputText value="#{showCalendarBean.eventSelectedDeleted.place}" />

                                <p:commandButton id="Ok" value="Ok" action="#{showCalendarBean.deleteCancellation()}" ajax="true" styleClass="ui-confirmdialog-no" icon="ui-icon-close">
                                    <f:setPropertyActionListener value="#{showCalendarBean.eventSelectedDeleted}" target="#{showCalendarBean.eventoSelezionatoEliminato}" /> 
                                </p:commandButton>
                            </p:panelGrid>
                        </p:outputPanel>
                    </h:form>    
                </p:dialog>
                <p:dataList id="modification_list" value="#{showCalendarBean.eventModificationList}" var="modification" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                    <f:facet name="header">
                        Modification List
                    </f:facet>
                    <p:commandLink update=":formModification:modificationDetail" oncomplete="PF('cancellationDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search" style="float:left;margin-right:10px">
                        <f:setPropertyActionListener value="#{modification}" target="#{showCalendarBean.eventSelectedModified}" />
                        <h:outputText value="#{modification.name}, #{modification.place}" />
                    </p:commandLink>
                    <h:outputText id="event_review" style="display:inline-block">#{modification.name}, #{modification.place}</h:outputText>
                    <h:outputText value="#{modification.name}, #{modification.place}" style="display:inline-block"/>
                </p:dataList>

                <p:dialog id="evmDtsWindow" header="Modified Events" widgetVar="cancellationDialog" modal="true" showEffect="blind" resizable="false">
                    <h:form id="formModification">
                        <p:outputPanel id="modificationDetail" style="text-align:center;">
                            <p:panelGrid  columns="2" rendered="#{not empty showCalendarBean.eventSelectedModified}" columnClasses="label,value">

                                <h:outputText value="Name:" />
                                <h:outputText value="#{showCalendarBean.eventSelectedModified.name}" />

                                <h:outputText value="Starting Date" />
                                <h:outputText value="#{showCalendarBean.eventSelectedModified.starting_date}" />

                                <h:outputText value="Place" />
                                <h:outputText value="#{showCalendarBean.eventSelectedModified.place}" />

                                <p:commandButton id="Ok" value="Ok" action="#{showCalendarBean.deleteModification()}" ajax="true" styleClass="ui-confirmdialog-no" icon="ui-icon-close">
                                    <f:setPropertyActionListener value="#{showCalendarBean.eventSelectedModified}" target="#{showCalendarBean.eventoSelezionatoModificato}" /> 
                                </p:commandButton>
                            </p:panelGrid>
                        </p:outputPanel>
                    </h:form>    
                </p:dialog>

                <p:dataList id="weather_list" value="#{showCalendarBean.badWeatherEvents}" var="bad_weather" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                    <f:facet name="header">
                        Bad Weather Alerts 
                    </f:facet>
                    <p:commandLink update=":formAlerts:alertsDetail" oncomplete="PF('alertsDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search" style="float:left;margin-right:10px">
                        <f:setPropertyActionListener value="#{bad_weather}" target="#{showCalendarBean.eventSelectedBadWeather}" />
                        <h:outputText value="#{bad_weather.name}, #{bad_weather.place}" />
                    </p:commandLink>
                    <h:outputText id="event_review" style="display:inline-block">#{bad_weather.name}, #{bad_weather.place}</h:outputText>
                    <h:outputText value="#{bad_weather.name}, #{bad_weather.place}" style="display:inline-block"/>
                </p:dataList>

                <p:dialog id="evbDtsWindow" header="Event With Bad Weather" widgetVar="alertsDialog" modal="true" showEffect="blind" resizable="false">
                    <h:form id="formAlerts">
                        <p:outputPanel id="alertsDetail" style="text-align:center;">
                            <p:panelGrid  columns="2" rendered="#{not empty showCalendarBean.eventSelectedBadWeather}" columnClasses="label,value">

                                <h:outputText value="Name:" />
                                <h:outputText value="#{showCalendarBean.eventSelectedBadWeather.name}" />

                                <h:outputText value="Starting Date" />
                                <h:outputText value="#{showCalendarBean.eventSelectedBadWeather.starting_date}" />

                                <h:outputText value="Place" />
                                <h:outputText value="#{showCalendarBean.eventSelectedBadWeather.place}" />

                                <h:outputText value="Expected Weather" />
                                <h:outputText value="#{showCalendarBean.eventSelectedBadWeather.expectedWeather.name}" />

                                <p:spacer></p:spacer>
                                <p:commandButton id="read" value="Ok" action="#{showCalendarBean.readAlert()}" ajax="true" styleClass="ui-confirmdialog-no"></p:commandButton>
                            </p:panelGrid>
                        </p:outputPanel>
                    </h:form>    
                </p:dialog>

                <p:dataList id="rescheduling_list" value="#{showCalendarBean.reschedulingEvents}" var="event" type="unordered" itemType="none" paginator="true" rows="10" styleClass="paginated">
                    <f:facet name="header">
                        Rescheduling Suggestions
                    </f:facet>
                    <p:commandLink update=":reform:reschedulingDetail" oncomplete="PF('suggestionDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search" style="float:left;margin-right:10px">
                        <f:setPropertyActionListener value="#{event}" target="#{showCalendarBean.selectedReschedulingEvent}" />
                        <h:outputText value="#{event.name}, #{event.place}" />
                    </p:commandLink>
                    <h:outputText id="event_review" style="display:inline-block">#{event.name}, #{event.place}</h:outputText>
                    <h:outputText value="#{event.name}, #{event.place}" style="display:inline-block"/>
                </p:dataList>
                <p:dialog id="erDtsWindow" header="Rescheduling Suggestion" widgetVar="suggestionDialog" modal="true" showEffect="blind" resizable="false">
                    <h:form id="reform">
                        <p:outputPanel id="reschedulingDetail" style="text-align:center;">
                            <p:panelGrid  columns="2" rendered="#{not empty showCalendarBean.selectedReschedulingEvent}" columnClasses="label,value">

                                <h:outputText value="Name:" />
                                <h:outputText value="#{showCalendarBean.selectedReschedulingEvent.name}" />

                                <h:outputText value="Starting Date" />
                                <h:outputText value="#{showCalendarBean.selectedReschedulingEvent.starting_date}" />

                                <h:outputText value="Starting Time" />
                                <h:outputText value="#{showCalendarBean.selectedReschedulingEvent.startingTime.hours}:#{showCalendarBean.selectedReschedulingEvent.startingTime.minutes}" />

                                <h:outputText value="Place" />
                                <h:outputText value="#{showCalendarBean.selectedReschedulingEvent.place}" />

                                <h:outputText value="Expected Weather" />
                                <h:outputText value="#{showCalendarBean.selectedReschedulingEvent.expectedWeather.name}" />

                                <h:outputText value="New Suggested Date" />
                                <h:outputText value="#{showCalendarBean.reSuggestion.reschedulingDate.date}/#{showCalendarBean.reSuggestion.reschedulingDate.month+1}/#{showCalendarBean.reSuggestion.reschedulingDate.year+1900}" />


                                <p:commandButton id="No" value="No" action="#{showCalendarBean.refuseRescheduling()}" ajax="true" styleClass="ui-confirmdialog-no" icon="ui-icon-close" ></p:commandButton>
                                <p:commandButton id="Yes" value="Yes" action="#{showCalendarBean.acceptRescheduling()}" ajax="true" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"></p:commandButton>
                            </p:panelGrid>
                        </p:outputPanel>
                    </h:form>
                </p:dialog>             
    </h:body>
</html>
